package com.ks.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ks.entity.Book;
import com.ks.feign.ServiceFeign;
import com.ks.handler.CustomBlockHandler;
import com.ks.mapper.BookMapper;
import com.ks.service.BookService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.awt.print.Pageable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: scrapy
 * @description:
 * @author: Liu Weidong
 * @create: 2023-01-01 19:19
 **/
@RestController
@RequestMapping("/sql")
public class BookController {

    @Resource
    private BookMapper bookMapper;

    @Resource
    private BookService bookService;


    @Resource
    private ServiceFeign serviceFeign;


    private ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 16,60L, TimeUnit.SECONDS,new ArrayBlockingQueue<>(1000));


    @GetMapping("/hello")
    public String getHello(){
        return "hello word";
    }


    @GetMapping("/save")
    @SentinelResource(value = "info")//限流，配合终端使用。终端设置的一秒内只允许访问一次，访问次数多了就进入CustomBlockHandler中的异常
    public String getUserInfo() {
        return "success";
    }


    @GetMapping("/query")
    public String query(){
        return serviceFeign.query();
    }
    @GetMapping("/get")
    public Book get(){
        return bookService.findOne();
    }

    @GetMapping("/findByPage")
    public Page<Book> get(Integer pageNo, Integer pageSzie){
        return bookService.findByPage(pageNo, pageSzie);
    }






}
